package cn.yitun.chat.yitunserverimapicore.business.file.action;

import cn.yitun.chat.yituncommonmessage.ExceptionEnum;
import cn.yitun.chat.yituncommonmessage.YitunException;
import cn.yitun.chat.yituncommonmessage.impl.HeadImpl;
import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yituncommonutil.YitunCollectionUtil;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitungeneral.annotation.action.ActionMapping;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.common.FileDataDto;
import cn.yitun.chat.yitunserverimcore.general.main.push.file.FilePush;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 
 * @author yitun
 *
 */
@Component
@ActionMapping(value = ActionTypeConstant.FILE_ACTION_PUSH)
public class FileAction {

	@Resource
	FilePush filePush;

	/**
	 * 服务地址
	 * 
	 * @author: yitun
	 * @createDate: 2017�?4�?14�? 上午9:16:47
	 * @update: yitun
	 * @updateDate: 2017�?4�?14�? 上午9:16:47
	 */
	@ActionMapping(value = "1.1.0001")
	public ResultMessage getFileServer() {
//		String category = "server.path.file";
//		String key = "file.server.http.url";
		String value = "";// ConfigBox.get(category, key);

		ResultMessage message = new ResultMessage();
		message.bodyPut("fileServerUrl", value);
		return message;
	}

	@ActionMapping(value = "1.1.0003")
	public ResultMessage getUserRemoteAddress(@JsonDefine("data") FileDataDto query) {
		ResultMessage message = new ResultMessage();
		message.bodyPut("remoteAddress", null);
		return message;
	}

	/**
	 * 获取对方支持接受文件方式信息
	 * 
	 * @author: yitun
	 * @createDate: 2017�?4�?14�? 上午9:17:15
	 * @update: yitun
	 * @updateDate: 2017�?4�?14�? 上午9:17:15
	 */
	@ActionMapping(value = "1.1.0004")
	public void getOppositeFileAcceptInfo(
			HeadImpl head,
			@JsonDefine("data") FileDataDto query) {
	    if (query.getSendUserId() == null || query.getReceiveUserId() == null)
	        throw new YitunException(ExceptionEnum.LOSE_FILED);

		filePush.pushGetOppositeFileAcceptInfo(head.getKey(), query);
	}

	/**
	 * 回应对方请求控制电脑
	 * 
	 * @author: yitun
	 * @createDate: 2017�?4�?14�? 上午9:17:30
	 * @update: yitun
	 * @updateDate: 2017�?4�?14�? 上午9:17:30
	 */
	@ActionMapping(value = "1.1.0005")
	public void returnFileAcceptInfo(
			HeadImpl head,
			@JsonDefine("data") FileDataDto query) {
        if (query.getSendUserId() == null || query.getReceiveUserId() == null ||
				YitunCollectionUtil.isEmpty(query.getAcceptTypeList()))
            throw new YitunException(ExceptionEnum.LOSE_FILED);

		filePush.pushReturnFileAcceptInfo(head.getKey(), query);
	}

	@ActionMapping(value = "1.1.0006")
	public void sendOfflineFile(
			HeadImpl head,
			@JsonDefine("data") FileDataDto query) {
        if (query.getSendUserId() == null || query.getReceiveUserId() == null)
            throw new YitunException(ExceptionEnum.LOSE_FILED);

		filePush.pushSendOfflineFile(head.getKey(), query);
	}

	@ActionMapping(value = "1.1.0007")
	public void requestOnline(
			HeadImpl head,
			@JsonDefine("data") FileDataDto query) {

        if (query.getSendUserId() == null || query.getReceiveUserId() == null ||
                YitunStringUtil.isEmpty(query.getActionType()) ||
                YitunStringUtil.isEmpty(query.getCode()) ||
                YitunStringUtil.isEmpty(query.getMessage()))
            throw new YitunException(ExceptionEnum.LOSE_FILED);

		filePush.pushResponse(head.getKey(), query);
	}

	@ActionMapping(value = "1.1.0008")
	public void response(
			HeadImpl head,
            @JsonDefine("data") FileDataDto query) {

        if (query.getSendUserId() == null || query.getReceiveUserId() == null)
            throw new YitunException(ExceptionEnum.LOSE_FILED);

		filePush.pushCancel(head.getKey(), query);
	}
}
